package com.estar.platform.caseInfo.controller;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.jeecgframework.core.common.controller.BaseController;
import org.jeecgframework.core.common.exception.BusinessException;
import org.jeecgframework.core.common.model.json.AjaxJson;
import org.jeecgframework.core.util.ResourceUtil;
import org.jeecgframework.web.system.pojo.base.TSUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.estar.app.business.common.service.AppService;
import com.estar.platform.caseInfo.entity.TmblSurveyInfoEntity;

//案件抽查的controller
@Controller
@RequestMapping("/surveySpotCheck")
@Scope("prototype")
public class SurverySpotCheck extends BaseController{
	@Autowired
	AppService appService;
	private static final Logger logger = Logger.getLogger(SurverySpotCheck.class);
	
	@RequestMapping(params = "surveyPass")
	@ResponseBody
	public String surveyPass(HttpServletRequest request, HttpServletResponse response) {
		//AjaxJson j = new AjaxJson();
		boolean flag=false;
		try{
			String reportNo = request.getParameter("reportNo"); // 案件流水号
			TmblSurveyInfoEntity surveyInfo=appService.findUniqueByProperty(TmblSurveyInfoEntity.class,"reportNo", reportNo);
			surveyInfo.setSpotCheck("p");
			surveyInfo.setSpotCheckInfo("");
			TSUser user = ResourceUtil.getSessionUserName();// 通过session获取登录用户
			surveyInfo.setSpotCheckUser(user.getUserName());
			surveyInfo.setSpotCheckDate(new Date());
			appService.updateEntitie(surveyInfo);
			flag=true;
		}catch(Exception e) {
			
			logger.error("案件抽查系统异常：",e);
			e.printStackTrace();
		}
		String json="{\"success\":"+flag+"}";
		return json;
	}
	
	@RequestMapping(params = "surveyNoPass")
	@ResponseBody
	public String surveyNoPass(HttpServletRequest request, HttpServletResponse response) {
		//AjaxJson j = new AjaxJson();
		boolean flag=false;
		try{
			String reportNo = request.getParameter("reportNo"); // 案件流水号
			String mess=request.getParameter("tex");
			TmblSurveyInfoEntity surveyInfo=appService.findUniqueByProperty(TmblSurveyInfoEntity.class,"reportNo", reportNo);
			surveyInfo.setSpotCheck("f");
			surveyInfo.setSpotCheckInfo(mess);
			TSUser user = ResourceUtil.getSessionUserName();// 通过session获取登录用户
			surveyInfo.setSpotCheckUser(user.getUserName());
			surveyInfo.setSpotCheckDate(new Date());
			appService.updateEntitie(surveyInfo);
			flag=true;
		}catch(Exception e) {
	
			logger.error("案件抽查系统异常：",e);
			e.printStackTrace();
		}
		String json="{\"success\":"+flag+"}";
		return json;
	}
	
	@RequestMapping(params = "toSurveyNoPass")
	public ModelAndView list(HttpServletRequest request) {
		return new ModelAndView("gdia/caseInfo/carInfoSpotCheck");
	}

	
}
